package com.edu.dao.impl;

import com.edu.dao.*;
import com.edu.data.News;
import com.edu.data.Product;
import com.edu.data.ProductCategory;
import com.edu.entity.Pager;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

@Repository
public class IndexDaoImpl implements IndexDao {
    SqlSession sqlSession= MyBatisUtil.createSession();
    NewsMapper newsMapper = sqlSession.getMapper(NewsMapper.class);
    ProductMapper productMapper = sqlSession.getMapper(ProductMapper.class);
    ProductCategoryMapper productCategoryMapper = sqlSession.getMapper(ProductCategoryMapper.class);
    //查询所有的信息
    @Override
    public List<Product> getAllProduct() throws SQLException {
        List<Product> productList = productMapper.getAllProduct();
        return productList;
    }
    //查询二级分类下的信息
    @Override
    public List<Product> getClassProduct(int id) {
        List<Product> productList = productMapper.getClassProduct(id);
        return productList;
    }

    @Override
    public List<News> getnews() throws SQLException {
        List<News> newsList = newsMapper.getAllNews();
        return newsList;
    }

    @Override
    public List<ProductCategory> getAllProductCategory() {
        List<ProductCategory> productCategoryList = productCategoryMapper.getAllProductCategory();
        return productCategoryList;
    }

    @Override
    public long getTotal() {
        return 0;
    }

    @Override
    public List<Product> selectByPage(Pager pager) {
        List<Product>contactList=productMapper.selectByPage(pager);
        return contactList;
    }
}
